package com.xk.springboot.task;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author:Teacher黄
 * @date:Created at 2020/04/13
 */
@Component
public class TimerTask {




    /*@Scheduled(fixedDelay = 2000)
    public void task1(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        System.out.println(sdf.format(new Date()));
    }*/


    @Scheduled(cron = "10 * * * * *")
    public void task2(){
        // 在数据库做一个配置开关
        // 每次执行的时候读取开关配置
        Integer open = 0;
        if(open.equals(1)){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            System.out.println(sdf.format(new Date()));
        }

    }


}
